<template>
  <div>
    <van-nav-bar safe-area-inset-top placeholder :title="$t('Meter')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('MeterFunction')" name="1">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.MeterFunctionValue" :reg="140"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Meter1ID')" name="2">
          <pfLockInPointPTVue :setMin="1" :setMax="200" :setValue.sync="LocalArr.Meter1IDValue" :reg="141"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Meter2ID')" name="3">
          <pfLockInPointPTVue :setMin="1" :setMax="200" :setValue.sync="LocalArr.Meter2IDValue" :reg="142"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="4">
          <resetINVEnergyPTVue :setName="$t('ResetMeter1Energy')" :reg="134"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetMeter2Energy')" :reg="143"></resetINVEnergyPTVue>
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import languagePTVue from '../../../components/Language/LanguagePT'
import pfLockInPointPTVue from '../../../components/PfLockInPoint/PfLockInPointPT'
import resetINVEnergyPTVue from '../../../components/ResetINVEnergy/ResetINVEnergyPT'

export default {
  components:{
    languagePTVue,
    pfLockInPointPTVue,
    resetINVEnergyPTVue
  },
  data(){
    return {
      inverterType:localStorage.getItem('inverterType'),
      isLoading:false,
      activeNames:[],
      toggleArr:[this.$t('Disable'),this.$t('Enable')],
      LocalArr:{
        MeterFunctionValue:'',
        Meter1IDValue:'',
        Meter2IDValue:''
      }
    }
  },
  methods: {
    onClickLeft(){
      if(this.inverterType==9){
        this.$router.push({path:'/x1acadvanced'});
      }else{
        this.$router.push({path:'/setting'});
      }
    },
    //获取设置数据
    async getData(){
      this.comm.loadingShow();
      let datas = await this.SETAPI.setGetDataPT(localStorage.getItem('domain'),{'tokenId':localStorage.getItem('tokenId'),'sn':localStorage.getItem('wifiSN')});
      if(datas.result!=null&&datas.result!="tokenId不合法!"){
        let dataArr=datas.result;
        this.LocalArr.MeterFunctionValue=dataArr[146];
        this.LocalArr.Meter1IDValue=dataArr[147];
        this.LocalArr.Meter2IDValue=dataArr[148];
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    onRefresh(){
      this.isLoading = false;
      for(let i in this.LocalArr){
        this.LocalArr[i]='';
      }
      this.getData();
    }
  },
  mounted(){
    this.getData();
  }
}
</script>

<style scoped lang="less">

</style>
